Page({
  /**
   * 页面的初始数据
   */
  data: {
    flash: "on", // 闪光灯
    flashList: [
      { name: "打开", code: "on" }, { name: "自动", code: "auto" }, { name: "关闭", code: "off" },
    ],

    aspectRatio: "square", // 纵横比
    aspectRatioList: [
      { name: "正方形", code: "square" }, { name: "长方形", code: "narrow" }
    ],

    resolution: "high", // 分辨率
    resolutionList: [
      { name: "小", code: "low" }, { name: "中", code: "medium" }, { name: "大", code: "high" },
    ],
  },

  // 切换设置
  selectSetting(e) {
    const { type, item } = e.currentTarget.dataset;
    if (type == "flash") {
      this.setData({
        flash: item.code
      })
    }

    if (type == "aspectRatio") {
      this.setData({
        aspectRatio: item.code
      })
    }

    if (type == "resolution") {
      this.setData({
        resolution: item.code
      })
    }

    const { flash, aspectRatio, resolution } = this.data;
    
    wx.setStorageSync("setting", {
      flash,
      aspectRatio,
      resolution,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const setting = wx.getStorageSync("setting");
    if (setting) {
      const { flash, aspectRatio, resolution } = setting;
      this.setData({
        flash,
        aspectRatio,
        resolution,
      })
    }
  },
})